package com.ccw.dynamic;

import javassist.CannotCompileException;
import javassist.NotFoundException;

import com.ccw.dynamic.impl.SuperMethodInfo;

/**
 * This interface will modify or new class.If you want to modify a class,this
 * class must not be used before modify<br>
 * 1.You can add java code to before or after method.<br>
 * 2.You can add code like"private org.apache.log4j.Logger serviceLogger = org.apache.log4j.Logger.getLogger(this.getClass());"
 * .<br>
 * 3.You can add code
 * like"Logger serviceLogger = Logger.getLogger(this.getClass());",if you add
 * code like this,the import "org.apache.log4j.Logger" must be set.<br>
 * 4.A class could be modify once.<br>
 * 
 * @author ccwang
 * 
 */
public interface SsistManager {

	/**
	 * create a new class
	 */
	public final static int NEW_CLASS = 0;

	/**
	 * modify class
	 */
	public final static int MODIFY_CLASS = 1;

	/**
	 * modify class by new method
	 */
	public final static int MODIFY_CLASS_NEW_METHOD = 2;

	/**
	 * add code before method<br>
	 * 1. Code will be also add in to Constructor.
	 * 
	 * @param code
	 * @return boolean
	 */
	public boolean addBeforeCode(String code);

	/**
	 * add code after method<br>
	 * 1. Code will be also add in to Constructor.
	 * 
	 * @param code
	 * @return boolean
	 */
	public boolean addAfterCode(String code);

	/**
	 * 1.If you want to add field like add import class like
	 * "Logger serviceLogger = Logger.getLogger(this.getClass());"
	 * ,"org.apache.log4j.Logger" must be add into this interface.<br>
	 * 2.Also you can add field like"private org.apache.log4j.Logger serviceLogger = org.apache.log4j.Logger.getLogger(this.getClass());"
	 * .<br>
	 * 3.I suggest you to used like point two,this method will be safe.
	 * 
	 * @param code
	 * @return
	 */
	public boolean addImportPackage(String code);

	/**
	 * add field
	 * 1.Please see method addImportPackage(String code).
	 * 
	 * @param code
	 * @return boolean
	 */
	public boolean addField(String code);

	/**
	 * add method
	 * 
	 * @param code
	 * @return boolean
	 */
	public boolean addMethod(SuperMethodInfo superMethodInfo);

	/**
	 * process operate<br>
	 * 1.If you want to create a field in before code,and use it in after
	 * code,you must set type=SsistManager.MODIFY_CLASS
	 * 
	 * @param type
	 *            process type you can new class,modify class,modify class by
	 *            new method
	 * @return boolean
	 */
	public Class<?> process(int type, String targetClass)
			throws NotFoundException, CannotCompileException,
			InstantiationException, IllegalAccessException;

	/**
	 * add mtch rule<br>
	 * 1. If you don't want the code will be add into Constructor,please be
	 * careful don't let the Constructor be matched.
	 * 
	 * @param matchRule
	 */
	public void addMatchRule(String matchRule);

}
